{-# LANGUAGE ScopedTypeVariables        #-}
{-# LANGUAGE OverloadedStrings          #-}

module DemoMon where

import Ochre
import Ochre.Language.Gens
import Ochre.Language.GensRaw

import Control.Monad


-- Uncommenting the addition correctly fails...
dummy01 :: ZakIx
dummy01 = zakIx 1 {-  + zakIx 2  -}


-- generate with 0dbfs


demo01 = either putStr putStr $ compileOrch default_opts $ do
    giOne <- initglobal ("giOne" ::: IRate) 0.0
    giSine <- ftgen ("giSine" ::: IRate) 0 1024 $ gen_sine 1.0
    giSamp <- load_file ("giSamp" ::: IRate) "mysamp.wav"
    instr 101 instr101
    instr 102 instr102
    instr 103 instr103
    instr 104 instr104


table1 :: TableIx
table1 = tableIx 1

instr101 :: Instr
instr101 = definstr $ return $ do 
    asig <- defsig ARate (oscil 1.0 440.0 table1)
    out asig



instr102 :: Instr
instr102 = definstr $ do 
    ihz <- defvar "ihz" (pfield 5 :: IFloat)
    return $ do 
      asig <- defsig ARate (oscil 1.0 (signalA ihz) table1)
      out asig


instr103 :: Instr
instr103 = definstr $ do
   ihz   <- defvar "ihz" (pfield 5 :: IFloat)
   return $ do 
     asig1 <- defsig ARate (oscil 1.0 (signalA ihz) table1)
     asig2 <- defsig ARate (oscil 1.0 (signalA ihz + 220) table1)
     out (asig1 .+. asig2)




instr104 :: Instr
instr104 = definstr $ do 
    ihz <- defvar "ihz" (pfield 5 :: IFloat)
    return $ do
      asig1 <-  defsig ARate (oscil 1.0 (signalA ihz) table1)
      asig1 &~= 1.0 * asig1
      out asig1



envelope1 :: IFloat -> GenKSig
envelope1 idur = expseg                    0.01 
                        [ 0.002        ::: 1.00
                        , idur - 0.002 ::: 0.01
                        ]